<?php
include_once "func.php";
include_once "func_sms.php";

ini_set('display_errors', '0');
error_reporting(0);//禁用错误报告 

// data:{ englishname:englishname,chinesename:chinesename,
// nationality:nationality,contactnumber:contactnumber,email:email,place:place},

$fullname = $_POST['fullname'];
$phonenumber = $_POST['phonenumber'];
$qqnumber = $_POST['qqnumber'];
$sex = $_POST['sex'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$birthday = $_POST['birthday'];
$sporttypes = $_POST['sporttypes'];
$sporttitle = $_POST['sporttitle'];
$orthertype = $_POST['orthertype'];
$invitecode_f = $_POST['invitecode_f'];


 
if($fullname==''||$sporttypes==''||$phonenumber==''){
	$return = array(
	    'result' => 3
	);
	ajax_return($return);
}


if(!preg_match("/1[3458]{1}\d{9}$/",$phonenumber)){  
	$return = array(
	    'result' => 4
	);
	ajax_return($return);
 }

//TODO 检查手机号是否已经注册


//生成一个随机数
$smscode = substr(rand(), 0, 4); 
send_sms( $smscode, $phonenumber);
 
//生成邀请码
$invitecode = substr(rand(), 0, 6); 


 
$sql = "insert into coach(fullname,height,weight,birthday,phonenumber,qqnumber,sex,sporttypes,sporttitle,orthertype,createdate,smscode,invitecode,invitecode_f) 
values('$fullname','$height','$weight','$birthday','$phonenumber','$qqnumber','$sex','$sporttypes','$sporttitle','$orthertype',NOW(),'$smscode','$invitecode','$invitecode_f')";
$res = $db->query($sql);
 
if($res){
 	$return = array(
	    'result' => 1,
	    'insert_id' => mysql_insert_id()
	);
	ajax_return($return);
}

 
  
?>